package org.imis.action;

import java.util.List;
import java.util.Map;

import org.imis.domain.*;
import org.imis.service.NewsManage;

import com.opensymphony.xwork2.ActionContext;

public class NewsConditionAction {
	private NewsManage newsManage;
	private Map request; 
	private String id;
	private String table;
	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public NewsManage getNewsManage() {
		return newsManage;
	}

	public void setNewsManage(NewsManage<?> newsManage) {
		this.newsManage = newsManage;
	}
	
	public String execute() throws ClassNotFoundException
	{
		
		request = (Map)ActionContext.getContext().get("request");  
		List<Object> list1 = newsManage.findNewsByPage("from "+table, 1, 5, 5);
		
		request.put("qlist", list1);
		if(table.equals("Forum"))
		{
		Forum news = (Forum) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		else if(table.equals("Information"))
		{
		Information news = (Information) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		else if(table.equals("News"))
		{
		News news = (News) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		else if(table.equals("Notice"))
		{
		Notice news = (Notice) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		else if(table.equals("PConsult"))
		{
		PConsult news = (PConsult) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		else if(table.equals("RConsult"))
		{
		RConsult news = (RConsult) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		else if(table.equals("StudentShip"))
		{
		StudentShip news = (StudentShip) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		else if(table.equals("StuGroup"))
		{
		StuGroup news = (StuGroup) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		else if(table.equals("StuHonor"))
		{
		StuHonor news = (StuHonor) newsManage.findOneList(table,Integer.parseInt(id));
		news.setClick(news.getClick()+1);
		newsManage.saveAlter(news);
		request.put("news", news);
		}
		return "success";
		
	}


}
